package cn.goktech.sports.modules.countryEmbargoGoods.api;

import cn.goktech.sports.common.annotation.RestAnon;
import cn.goktech.sports.common.entity.R;
import cn.goktech.sports.common.utils.CommonUtils;
import cn.goktech.sports.modules.countryEmbargoGoods.service.CountryEmbargoGoodsService;
import cn.goktech.sports.modules.importDataone.entity.BaseProhibited;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Objects;


@RestController
@RequestMapping("/rest/countryEmbargoGoods")
public class RestCountryEmbargoGoodsApi {

	@Resource(name = "countryEmbargoGoodsService")
	private CountryEmbargoGoodsService countryEmbargoGoodsService;

	//查询邮寄货物是否属于改目的地的禁运商品
//	@RequestMapping(value = "/isExist", method = RequestMethod.POST)
//	@RestAnon
//	public R isExist(@RequestBody JSONObject jsonObject) {
//		R r = new R();
//		System.out.println("jsonObject == " + jsonObject);
//		String countryId = jsonObject.get("countryId").toString();
//		String goodsName = jsonObject.get("goodsName").toString();
//		//查询寄往该目的地的该货物是否是禁运货物
//		int count = countryEmbargoGoodsService.isExist(countryId, goodsName);
//		if (count >= 1) {
//			return r.put("msg", "该货物属于目的地的违禁品");
//		}
//		return r.put("msg", "no");
//	}

	/**
	 * 查询违禁物品是否是目的地禁运商品
	 * 如果禁运，查出各国禁运清单
	 *
	 * @param params
	 * @return
	 */
	@RequestMapping(value = "/isExist", method = RequestMethod.POST)
	@RestAnon
	public R contraband(@RequestBody Map<String, Object> params) {
		List<BaseProhibited> list = countryEmbargoGoodsService.contraband(params);
		if (Objects.nonNull(list) && !list.isEmpty()) {
			//表示存在违禁品，查出各国违禁
			String goodsName = (String) params.get("goodsName");
			Map<String, Object> map = new HashMap<>();
			map.put("goodsName", goodsName);
			List<BaseProhibited> contraband = countryEmbargoGoodsService.contraband(map);
			return CommonUtils.msg(contraband);
		}
		//不存在就返回正常
		return R.error(200, "不是违禁品");
	}
}
